package com.hentie.tilelib;

import android.util.Log;

//This holds tileset information
public class Tileset {
	//The tileSet Name
	public String tileName;
	//The tileSet image
	public String tileImage;
	//Tile properties
	public int tileWidth;
	public int tileHeight;
	public int margins;
	public int spacing;
	public int drawOffsetX;
	public int drawOffsetY;
	public int imageWidth;
	public int imageHeight;
	float[] textureX;
	float[] textureY;
	float texWidth;
	float texHeight;
	public Tileset(String tileName, String tileImage,int tileWidth,int tileHeight,int imageWidth,int imageHeight)
	{
		//calculate the number of tiles in the image
		this.tileWidth = tileWidth;
		this.tileHeight = tileHeight;
		this.imageWidth = imageWidth;
		this.imageHeight = imageHeight;
		this.tileImage = tileImage;
		this.tileName = tileName;
		
		//Calculat the number of tiles per width and length
		int tileNumWidth = imageWidth/tileWidth;
		int tileNumHeight = imageHeight/tileHeight;
		
		texWidth = 1.0f/tileNumWidth;
		texHeight = 1.0f/tileNumHeight;
		
		textureX = new float[tileNumWidth*tileNumHeight];
		textureY = new float[tileNumWidth*tileNumHeight];
		int currentTile= 0;
		
		for(int i = 0; i < tileNumHeight; i++)
		{
			for(int j=0; j < tileNumWidth;j++)
			{
				textureX[currentTile] = j*texWidth;
				textureY[currentTile] = i*texHeight;
				currentTile++;
			}
		}
		
	}
	
	public float[] ReturnTexCoords(int tileID)
	{
		if(tileID < textureX.length && tileID > 0)
			return new float[]{textureX[tileID],textureY[tileID],texWidth,texHeight};
		else
		{
			Log.v("TILESET",String.valueOf(tileID));
			return new float[]{0,0,0,0};
		}
	}
	
}
